package com.yidu.ladder.base.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yidu.ladder.base.domain.Subset;
import com.yidu.ladder.base.domain.SubsetVo;
import com.yidu.ladder.base.service.SubsetService;

/**
 * 辅助档案控制器
 * @author bamboo
 *
 */
@Controller
@RequestMapping("base/subset")
public class SubsetController {
	@Autowired
	private SubsetService subsetService;
	/**
	 * 得到辅助档案service
	 * @return 辅助档案service
	 */
	public SubsetService getSubsetService() {
		return subsetService;
	}
	/**
	 * 修改辅助档案service
	 * @param subsetService 辅助档案service
	 */
	public void setSubsetService(SubsetService subsetService) {
		this.subsetService = subsetService;
	}
	
	/**
	 * 分页查询辅助档案
	 * @param subsetVo 辅助档案包装类
	 * @return 键值对数据
	 */
	@ResponseBody
	@RequestMapping(value="subsets",method=RequestMethod.GET)
	public Map<String,Object> selectAll(SubsetVo subsetVo){
		//调用service分页查询的方法并返回
		return subsetService.querySubsetWithPage(subsetVo);
	}
	/**
	 * 添加辅助档案
	 * @param subset 辅助档案
	 * @return 添加成功返回true，否则返回false
	 */
	@ResponseBody
	@RequestMapping(value="subset",method=RequestMethod.POST)
	public boolean addSubset(Subset subset) {
		//添加辅助档案并返回结果
		return subsetService.saveSubset(subset);
	}
	/**
	 * 修改辅助档案
	 * @param subset 辅助档案
	 * @return 修改成功返回
	 */
	@ResponseBody
	@RequestMapping(value="subset",method=RequestMethod.PUT)
	public boolean updateSubset(Subset subset) {
		//调用辅助档案service修改方法并返回结果
		return subsetService.updateSubset(subset);
		
	}
	/**
	 * 冻结或还原辅助档案
	 * @param subsetIds 辅助档案Id
	 * @param useable 是否可用
	 * @return 结果字符串
	 */
	@ResponseBody
	@RequestMapping(value="subset/{subsetId}/{useable}",method=RequestMethod.DELETE)
	public String frozenORrecoverSubset(@PathVariable("subsetId") String subsetIds, @PathVariable("useable") String useable) {
		//调用service层冻结或还原方法得到操作结果
		boolean result = subsetService.frozenOrRecovesubset(subsetIds, useable);
		//如果结果为false就返回fail字符串
		if(result==false) {
			return "fail";
		}
		//否则返回success字符串
		return "success";
		
	}
	/**
	 * 根据基础档案Id查询辅助档案
	 * @param archivesId 基础档案Id
	 * @return 辅助档案数据
	 */
	@ResponseBody
	@RequestMapping(value="subset/{archivesId}",method=RequestMethod.POST)
	public Map<String, Object> findByArchivesId(@PathVariable("archivesId") String archivesId){
		//调用辅助档案service根据基础档案Id查询辅助档案的方法，并返回
		return subsetService.findSubsetByArchivesId(archivesId);
		
	}
	/**
	 * 估计基础Id查询不同类型的辅助档案
	 * @return 辅助档案集合
	 */
	@ResponseBody
	@RequestMapping("findSubset")
	public List<Subset> findTypeByArchivesId(){
		//调用辅助档案service查询方法并返回
		return subsetService.findTypeByArchives();
	}
}
